//
//  L2UserDefaults.m
//  Lesson2
//
//  Created by Alexander Trifonov on 20.04.12.
//  Copyright (c) 2012 fgengine@gmail.com. All rights reserved.
//

#import "L2UserDefaults.h"

@implementation L2UserDefaults

- (void) execute
{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSString *result = [userDefaults objectForKey:@"name"];
    if([result length] > 0)
    {
        NSLog(@"name = %@", [userDefaults objectForKey:@"name"]);
        NSLog(@"age = %i", [userDefaults integerForKey:@"age"]);
        NSLog(@"student = %i", [userDefaults boolForKey:@"student"]);
    }
    else
    {
        NSLog(@"Add values to UserDefaults");
        [userDefaults setObject:@"Ira" forKey:@"name"];
        [userDefaults setInteger:24 forKey:@"age"];
        [userDefaults setBool:YES forKey:@"student"];
        [userDefaults synchronize];
    }
    
    NSLog(@"-L2UserDefaults-------------------------");
    
    [userDefaults setObject:@"Ivan" forKey:@"name"];
    NSLog(@"name = %@", [userDefaults objectForKey:@"name"]);
    
    NSLog(@"----------------------------------------");
    
    [userDefaults removeObjectForKey:@"age"];
    NSLog(@"age = %i", [userDefaults integerForKey:@"age"]);
    
    NSLog(@"----------------------------------------");
}

@end
